package com.loong.seller.business;

import com.loong.common.mybatis.business.AbstractBusiness;
import com.loong.seller.common.backend.param.CompanyQueryParam;
import com.loong.seller.model.Company;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description:
 * @Author: hzp
 * @Date: 2020-10-26 11:10
 */
@Repository
public class CompanyBusiness extends AbstractBusiness<Company> {
    /**
     * 分页查询
     * @param param
     * @return
     */
    public List<Company> query(CompanyQueryParam param){
        Condition condition = new Condition(Company.class);
        Example.Criteria criteria = condition.createCriteria();
        buildQueryCriteria(param,criteria);
        return findByCondition(condition);
    }
    //这里根据业务需求构造条件
    private void buildQueryCriteria(CompanyQueryParam param,Example.Criteria criteria){
        if(ObjectUtils.isNotEmpty(param.getName())){
            criteria.andEqualTo("name", param.getName());
           // criteria.andLike("name",param.getName());
        }
        if(ObjectUtils.isNotEmpty(param.getAddress())){
            criteria.andLike("address",param.getName());
        }


    }
}
